#! /bin/bash
NOW_DIR=$(cd -P $(dirname $0);pwd)
WWW_DIR=/home/www/
DOCKER_DIR=$NOW_DIR

chmod -R 777 "${WWW_DIR}"

#开启站点
WebKeyArr=$@

#WebArr=(dev.au.callie.com dev.ca.callie.com dev.fr.callie.com dev.uk.callie.com dev.www.callie.com dev.www.callie.de dev.it.callie.com dev.nl.callie.com dev.www.callie.es dev1.www.callie.com dev1.www.callie.de);

WebArr=(dev.fr.callie.com dev.uk.callie.com);

www_callie_com=${DOCKER_DIR}/dev.www.callie.com
cd ${www_callie_com} && docker-compose down
# 遍历数组并获取键和值
for index in "${!WebArr[@]}"; do
  key="$index"
  value="${WebArr[$index]}"
  echo "键：$key，值：$value"
  if [[ ! " ${WebKeyArr[*]} " =~ " $key " ]]; then
    echo "$value 站点不拷贝"
    continue
  fi
  echo "$value 站点准备拷贝"
  #docker站点目录
  siteDockerDir=${DOCKER_DIR}/$value
  echo "开始停止站点"
  cd ${siteDockerDir} && docker-compose down
  echo "删除旧的数据库"
  rm -rf ${siteDockerDir}/data/mysql5.7.18/data
  echo "复制美国库到站点"
  callie_data=${www_callie_com}/data/mysql5.7.18/data
  cp -ar ${callie_data} ${siteDockerDir}/data/mysql5.7.18/data
  cd ${siteDockerDir} && docker-compose up -d
done
cd ${www_callie_com} && docker-compose up -d
echo '复制数据库成功！！！'
